import Vue from 'vue'
import Router from 'vue-router'

// 按需（懒）加载
const LayoutHome = () => import(/* webpackChunkName: "LayoutHome" */ '@/layouts/home')
const Index = () => import(/* webpackChunkName: "Index" */ '@/views/index')
const proSupplier = () => import(/* webpackChunkName: "proSupplier" */ '@/views/products/supplier')
Vue.use(Router)

const base = `${process.env.BASE_URL}` // 动态获取二级目录
const router = new Router({
  mode: 'hash',
  base: base,
  routes: [
    {
      path: '/',
      redirect: '/index'
    },
    {
      path: '/home',
      name: 'LayoutHome',
      component: LayoutHome,
      children: [
        {
          path: '/index',
          name: 'Index',
          component: Index
        },
        {
          path: '/products/supplier',
          name: 'proSupplier',
          component: proSupplier
        }
      ]
    }
  ],
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }
})

export default router
